package com.hua.api.modules.home.rest;


import com.alibaba.fastjson.JSONObject;
import com.hua.api.core.activemq.ActiveMqConstant;
import com.hua.api.core.activemq.MqMessageBuilder;
import com.hua.api.core.activemq.consumer.event.EventConstant;
import com.hua.api.core.constants.Status;
import com.hua.api.core.framework.annotation.AnonymousAccess;
import com.hua.api.core.framework.util.Result;
import com.hua.api.modules.home.service.ActiveMqService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.Set;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/home")
public class HomeController {

    private final ActiveMqService activeMqService;

    @AnonymousAccess
    @RequestMapping("/activemq")
    public Result activemq(){
        JSONObject data = new JSONObject();
        data.put("order_no","911739582577204001");
        data.put("timestamp",System.currentTimeMillis());

        JSONObject message = MqMessageBuilder.builder()
                .target(ActiveMqConstant.hua000_api_queue)
                .event(EventConstant.event_order_created)
                .set("order_no","911739582577204001")
                .set("timestamp",System.currentTimeMillis())
                // .data(data)
                .build();
        activeMqService.sendDelayTopic(ActiveMqConstant.hua1000_api_topic,message.toJSONString(),6*1000l);
        // activeMqService.sendQueue(ActiveMqConstant.hua000_api_queue,message.toJSONString());
        return Result.of(data);
    }

    @AnonymousAccess
    @RequestMapping("/activemq1")
    public Result activemq1(){
        JSONObject data = new JSONObject();
        data.put("mequeued","傻大；三等分 add");
        data.put("dasha","2.com");
        activeMqService.sendTopic(ActiveMqConstant.hua1000_api_topic,data.toJSONString());
        return Result.of(data);
    }


    @AnonymousAccess
    @RequestMapping("/activemq3")
    public Result activemq3(){
        JSONObject data = new JSONObject();
        data.put("mequeued","a");
        data.put("dasha","2.com");
        activeMqService.sendDelayTopic(ActiveMqConstant.hua1000_api_topic,data.toJSONString(),3000l);
        return Result.of(data);
    }

    @AnonymousAccess
    @RequestMapping("/activemq4")
    public Result activemq4(){
        Set<Integer> set = new HashSet<>();
        set.add(820253094);
        set.add(820253102);
        String title="您有新的订单可报价接单提醒！";
        String context = "您有新的订单可报价接单，单号821756717449508001,请登录系统查看！";
        String type = "orderBid";
        activeMqService.onUserMesssage(set,title,context,type,1, Status.mp3_order_bid);
        return Result.success();
    }


    @AnonymousAccess
    @RequestMapping("/activemq5")
    public Result activemq5(){
        Set<String> set = new HashSet<>();
        set.add("13522328241");
        String context = "您有新的订单可报价接单，单号821756717449508001,请登录系统查看！";
        activeMqService.onSmsSender(set,context);
        return Result.success();
    }


}
